package com.example.endusation.service.impl;

import com.example.endusation.dao.UserFunctionDAO;
import com.example.endusation.dto.OptionsDTO;
import com.example.endusation.dto.UserInfoDTO;
import com.example.endusation.entity.*;
import com.example.endusation.service.UserFunctionService;
import com.example.endusation.util.WrapperResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserFunctionServiceImpl implements UserFunctionService {
    @Autowired
    private UserFunctionDAO userFunctionDAO;
    @Override
    public WrapperResponse queryLearnAddress(UserInfoDTO userInfoDTO) {
        List<LearnAddressDO> list = userFunctionDAO.queryLearnAddress(userInfoDTO.getUsername());
        return WrapperResponse.success(list);
    }

    @Override
    public WrapperResponse queryLearnVideo(UserInfoDTO userInfoDTO) {
        List<VideoDO> list = userFunctionDAO.queryVideo(userInfoDTO.getUsername());
        return WrapperResponse.success(list);
    }

    @Override
    public WrapperResponse queryLearnDocument(UserInfoDTO userInfoDTO) {
        List<DocumentDO> list = userFunctionDAO.queryDocument(userInfoDTO.getUsername());
        return WrapperResponse.success(list);
    }

    @Override
    public WrapperResponse queryLearnTest(UserInfoDTO userInfoDTO) {
        List<RecommendedExercises>  list = userFunctionDAO.queryExercises(userInfoDTO.getUsername());
        return WrapperResponse.success(list);
    }

    @Override
    public WrapperResponse queryExerciseDetil(String exerciseId) {
        List<ExercisesDO> list = userFunctionDAO.queryExerciseDetil(exerciseId);
        for(ExercisesDO exercisesDO:list){
            if(exercisesDO.getType().equals("选择")){
                List<OptionsDTO> list1 = userFunctionDAO.queryOptions(exercisesDO.getId());
                exercisesDO.setOptions(list1);
            }
        }
        return WrapperResponse.success(list);
    }
}
